//
//  RecordViewCtrl.m
//  HuoBao
//
//  Created by 于会海 on 15/12/3.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "InvitationViewCtrl.h"
#import "HBInvitRecordCtrl.h"
#import "HBMyInvitCodeCtrl.h"

@interface InvitationViewCtrl ()<InvitationViewPagerDataSource, InvitationViewPagerDelegate>
{
    int m;
    NSArray*   topLibArr;
    NSUInteger topIndex;
    UIView*    topAlertView;
    UILabel*   topAlertLabel;
    UIButton*  topAlertBtn;
    NSString*  topStatus;
}
@end

@implementation InvitationViewCtrl

- (void)viewDidLoad {
    self.title = @"邀请码";
    topLibArr = @[@"我的邀请码",@"邀请记录"];
    self.dataSource = self;
    self.delegate = self;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    [super viewDidLoad];
}

- (void)setTopAlertViewStatusWithString:(NSString*)status{
    topStatus = @"1";
    NSDictionary* dic = [NSDictionary dictionaryWithObject:topStatus forKey:@"myindex"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"setNewFream" object:dic];
}

- (void)deleteTopAlert:(UIButton*)button{
    UIButton* bigButton = button;
    if (bigButton.selected == YES) {
        [topAlertBtn setSelected:YES];
    }
    [UIView animateWithDuration:0.35 animations:^{
        CGRect myFrame=self.view.frame;
        myFrame.origin.y=20.0;
        self.view.frame=myFrame;
    }];
    topStatus = @"0";
    NSDictionary* dic = [NSDictionary dictionaryWithObject:topStatus forKey:@"myindex"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"setNewFream" object:dic];
    
}

- (void)viewWillAppear:(BOOL)animated{
    //这里接收过来的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showTopPoint:) name:Notification_showTopPoint object:nil];
    //如果导航栏是透明的话,滚动视图要想让内部视图不上下溢出，需要设置下面的属性为NO
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = NO;
//    [self showTopAlertView:YES];
}
- (void)buildLayout{
    
}
-(void)showTopPoint:(NSNotification*) notification{
    int n = [[[notification object] valueForKey:@"recordIndex"] intValue];
    topIndex = n;
    //设置顶部标签颜色
    UILabel* label = (UILabel*)[self.view viewWithTag:n+10];
    if (m ) {
        if (m-10 != n) {
            UILabel* label1 = (UILabel*)[self.view viewWithTag:m];
            [label1 setTextColor:[LCCommon getColor:@"929292"]];
        }
    }
    if (n == label.tag - 10) {
        [label setTextColor:[UIColor whiteColor]];
        m = n+10;
    }
}

#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPager:(InvitationViewPagerCtrl *)viewPager {
    return topLibArr.count;
}
- (UIView *)viewPager:(InvitationViewPagerCtrl *)viewPager viewForTabAtIndex:(NSUInteger)index {
    
    UILabel *label = [UILabel new];
    [label setFrame:CGRectMake(0, 0, SCREEN_WIDTH/topLibArr.count, 44)];
//    label.backgroundColor = [UIColor redColor];
    label.font = [UIFont systemFontOfSize:17];
    label.text = topLibArr[index];
    label.tag = index + 10;
    
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = [LCCommon getColor:@"929292"];
    [label sizeToFit];
    if (index == 0) {
        label.textColor = [LCCommon getColor:@"d2d2d2"];
        m = 0+10;
    }
    LLog(@"%@",topLibArr[index]);
    return label;
}
//在这里添加需要写入的viewController
- (UIViewController *)viewPager:(InvitationViewPagerCtrl *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {
    UIViewController* VC = [[UIViewController alloc] init];
    HBMyInvitCodeCtrl* homeVC= [[HBMyInvitCodeCtrl alloc] init];
    HBInvitRecordCtrl* actVC = [[HBInvitRecordCtrl alloc] init];
    if (index == 0) {
        VC = homeVC;
        homeVC.nav = self.navigationController;     
    }else if(index == 1){
        VC = actVC;
        actVC.nav = self.navigationController;
    }
    return VC;
}

#pragma mark - ViewPagerDelegate
- (CGFloat)viewPager:(InvitationViewPagerCtrl *)viewPager valueForOption:(InvitationViewPagerOption)option withDefault:(CGFloat)value {
    switch (option) {
        case InvitationPagerOptionTabWidth:
            return [[UIScreen mainScreen] bounds].size.width/topLibArr.count;
            break;
        default:
            break;
    }
    
    return value;
}

- (UIColor *)viewPager:(InvitationViewPagerCtrl *)viewPager colorForComponent:(InvitationViewPagerComponent)component withDefault:(UIColor *)color {
    
    switch (component) {
        case InvitationViewPagerIndicator:
            return [[LCCommon getColor:@"fa9838"] colorWithAlphaComponent:0.64];
            break;
        default:
            break;
    }
    
    return color;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
